<?php
/**
 * 描述：主页。
 * @final
 */
final class Exec_Index extends Exec
{
    public function Get()
    {
        #获取数据-最新采购信息数据
        $procurements=DB::GetRows('select * from procurement order by ID desc limit 0,15');
        View::Assign('Index_Procurement',$procurements);

        #获取数据-最新供应信息数据
        $supplies=DB::GetRows('select * from supply order by ID desc limit 0,15');
        View::Assign('Index_Supply',$supplies);

        #获取数据-产品超市
        $data=DB::GetRows('select * from supply where M_Supermarket_Is=TRUE order by M_Supermarket_Top_Is desc,M_Supermarket_Top_DateTime desc,ID desc limit 0,3');
        foreach($data as &$row)
        {            
            $row['ThumbnailPath']=Config::PATH_RELATIVE_ATTACHMENT_SUPPLY.'/'.$row['ThumbnailPath'];
        }
        View::Assign('Index_Supermarket',$data);

        #获取数据-船厂订单
        $data=DB::GetRows('select * from news where SubclassID='.DAO_NewsClass::SHIPYARD_ORDERSHEET_ID.' and M_IsDelete=FALSE order by ID desc limit 0,6');
        View::Assign('NewsClass_ShipyardOrdersheet_ID',DAO_NewsClass::SHIPYARD_ORDERSHEET_ID);
        View::Assign('Index_News_ShipyardOrdersheet',$data);

        #获取数据-船配订单
        $data=DB::GetRows('select * from news where SubclassID='.DAO_NewsClass::ANCILLARY_ORDERSHEET_ID.' and M_IsDelete=FALSE order by ID desc limit 0,6');
        View::Assign('NewsClass_AncillaryOrdersheet_ID',DAO_NewsClass::ANCILLARY_ORDERSHEET_ID);
        View::Assign('Index_News_AncillaryOrdersheet',$data);
        
        #获取数据-诚信供应商
        $sql='select * from account ';
        $sql=$sql.'where not exists(select * from account_locked where account.Username=account_locked.Account) ';                      //不锁定
        $sql=$sql.'and not exists(select * from account_delete where account.Username=account_delete.Account) ';                        //没删除
        $sql=$sql.'and exists(select * from account_email_verification where account.Username=account_email_verification.Account) ';    //己通过邮件验证
        $sql=$sql.'and exists(select * from account_integrity where account.Username=account_integrity.Account)';                       //是诚信供应商
        $sql=$sql.'order by Datetime desc limit 0,4 ';
        $data=DB::GetRows($sql);
		foreach($data as &$row)
		{
			$row['Logo']=Config::PATH_RELATIVE_ATTACHMENT_LOGO.'/'.$row['Logo'];
		}
        View::Assign('Supplier_Integrity',$data);

        #获取数据-最新企业信息
        $sql='select * from account ';
        $sql=$sql.'where not exists(select * from account_locked where account.Username=account_locked.Account) ';                      //不锁定
        $sql=$sql.'and not exists(select * from account_delete where account.Username=account_delete.Account) ';                        //没删除
        $sql=$sql.'and exists(select * from account_email_verification where account.Username=account_email_verification.Account) ';    //己通过邮件验证
        $sql=$sql.'order by Datetime desc limit 0,7 ';
        $data=DB::GetRows($sql);
        View::Assign('Index_LatestCompany',$data);

        #获取数据-访谈
        $data=DB::GetRows('select * from interview order by ID desc limit 0,3');
        @$data[0]['ThumbnailPath']=Config::PATH_RELATIVE_ATTACHMENT_TEMP.'/'.@$data[0]['ThumbnailPath'];
        View::Assign('Index_Interview_Topside',@$data[0]);
        View::Assign('Index_Interview',array_slice($data,1,count($data)));

        #获取数据-专题
        $data=DB::GetRows('select * from topic order by ID desc limit 0,1');
        foreach($data as &$row)
        {
            $row['ThumbnailPath']=Config::PATH_RELATIVE_ATTACHMENT_TOPIC.'/'.$row['ThumbnailPath'];
        }
        View::Assign('Index_Topic',$data);

        #获取数据-观察
        $data=DB::GetRows('select * from news where M_IsDelete=FALSE and SubclassID='.DAO_NewsClass::OBSERVE_COMMENT_ID.' and (Thumbnail is not NULL and Thumbnail<>"") order by M_IsTop desc,M_IsTop_Datetime desc,ID desc limit 0,1');
        foreach($data as &$row)
        {
            $row['Thumbnail']=Config::PATH_RELATIVE_ATTACHMENT_NEWS.'/'.$row['Thumbnail'];
        }
        View::Assign('NewsClass_ObserveComment_ID',DAO_NewsClass::OBSERVE_COMMENT_ID);
        View::Assign('Index_Observe',$data);

        #获取数据-头条
        $data=DB::GetRows('select * from news where M_IsHeadline=TRUE and M_IsDelete=FALSE order by M_IsHeadline_Datetime desc,ID desc limit 0,1');
        if($data)
        {
            $data[0]['Content']=strip_tags($data[0]['Content']);
            $data[0]['Thumbnail']=Config::PATH_RELATIVE_ATTACHMENT_NEWS.'/'.$data[0]['Thumbnail'];
            $data[0]['M_HTMLFile']=Config::PATH_RELATIVE_CONTENT_NEWS.'/'.$data[0]['M_HTMLFile'];
        }
        View::Assign('Index_News_Headline',@$data[0]);

        #获取数据-推荐
        $data=DB::GetRows('select * from news where M_IsRecommend=TRUE and M_IsDelete=FALSE order by M_IsRecommend_Datetime desc limit 0,4');
        if($data)
        {
            foreach ($data as &$row)
            {
                $row['ClassName']=DAO_NewsClass::GetNameByID($row['ClassID']);
                $row['M_HTMLFile']=Config::PATH_RELATIVE_CONTENT_NEWS.'/'.$row['M_HTMLFile'];
            }
        }
        View::Assign('Index_News_Recommend',$data);

        #获取数据-排行        
        View::Assign('Index_News_Ranking',DAO_News::Ranking());

        #获取数据-船舶
        $data=DAO_News::Area_Class(DAO_NewsClass::SHIPYARD_ID,DAO_NewsClass::SHIPYARD_CONJUNCTURE_ID,11,7);
        View::Assign('Index_NewsShipyardTopside',$data['Topside']);
        View::Assign('NewsClass_Shipyard_ID',DAO_NewsClass::SHIPYARD_ID);
        View::Assign('Index_NewsShipyard',$data['Foreach']);

        #获取数据-船配
        $data=DAO_News::Area_Class(DAO_NewsClass::ANCILLARY_ID,DAO_NewsClass::ANCILLARY_NEWS_ID,12,7);
        View::Assign('NewsClass_Ancillary_ID',DAO_NewsClass::ANCILLARY_ID);
        View::Assign('Index_AncillaryTopside',$data['Topside']);
        View::Assign('Index_Ancillary',$data['Foreach']);


        #获取数据-航运
        $data=DAO_News::Area_Class(DAO_NewsClass::SHIPPING_ID,DAO_NewsClass::SHIPPING_MARKET_ID,10,6);
        View::Assign('Index_NewsShipping_Topside',$data['Topside']);
        View::Assign('NewsClass_Shipping_ID',DAO_NewsClass::SHIPPING_ID);
        View::Assign('Index_News_Shipping',$data['Foreach']);

        #获取数据-数据
        $data=DB::GetRows('select * from news where ClassID='.DAO_NewsClass::DATA_ID.' and M_IsDelete=FALSE order by ID desc limit 0,10');
        if($data)
        {
            foreach($data as &$row)
            {
                if((time()-strtotime($row['Datetime']))/3600/24<=1)
                    $row['IsNew']='TRUE';
                else
                    $row['IsNew']='FALSE';
            }
        }
        View::Assign('NewsClass_Data_ID',DAO_NewsClass::DATA_ID);
        View::Assign('Index_News_Data',$data);

        #获取最新船厂数据
        $data=DAO_Account::Shipyard(8);
        View::Assign('Index_LatestShipyard',$data);

        #获取数据-DM杂志
        $data=DB::GetRows('select * from DM order by ID desc limit 0,1');
        if($data)
        {
            $data=$data[0];
            $data['CoverLocation']=Config::PATH_RELATIVE_ATTACHMENT_TEMP.'/'.$data['CoverLocation'];
        }
        View::Assign('Index_DM',$data);

        #获取数据-电子期刊
        $data=DB::GetRows('select * from ejournal order by ID desc limit 0,6');
        View::Assign('Index_Ejournal',$data);

        #获取数据-合作展会
        $data=DB::GetRows('select * from exhibition_index where Isdisplay=1 order by ID desc limit 0,6');
        foreach($data as &$row)
        {
            $row['Logo']=Config::PATH_RELATIVE_ATTACHMENT_TEMP.'/'.$row['Logo'];
        }
        View::Assign('Index_Exhibition',$data);

        #获取数据-合作伙伴
        $data=DB::GetRows('select * from link order by M_OrderWeight desc');
        View::Assign('Index_Link',$data);

        #获取数据-友情链接
        $data=DB::GetRows('select * from partner order by M_OrderWeight desc');
        View::Assign('Index_Partner',$data);
        
        #渲染输出
        View::Display('index.tpl');
    }
}
?>